package com.lyf.design.practice.theory.structure.flyweight;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LYF
 * @date 2022/6/22
 */
class Point{
    public enum STATUS{ALIVE,DEAD}
    private Integer x,y;
    private STATUS status=STATUS.ALIVE;

    public STATUS getStatus() {
        return status;
    }

    public void setStatus(STATUS status) {
        this.status = status;
    }
}
class PointPool{
   static List<Point> pool =new ArrayList<>();
   static Point getPoint(){
        for(int i=0;i<pool.size();i++){
            if(pool.get(i).getStatus()==Point.STATUS.ALIVE){
                pool.get(i).setStatus(Point.STATUS.DEAD);
                return pool.get(i);
            }
        }
        Point point = new Point();
        point.setStatus(Point.STATUS.DEAD);
        pool.add(point);
        return point;
    }

    static void remove(Point point){
        pool.remove(point);
        point.setStatus(Point.STATUS.ALIVE);
        pool.add(point);
    }

}
public class PointTests {
    @Test
    public void test1(){
        Point point = PointPool.getPoint();
        System.out.println(point);
        PointPool.remove(point);
        point = PointPool.getPoint();
        System.out.println(point);
        System.out.println(PointPool.getPoint());

    }
}
